home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
UDPSUBR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-13
|
1KB
|
53 lines
/* Convert UDP header in mbuf to internal structure */
#include "global.h"
#include "mbuf.h"
#include "internet.h"
#include "netuser.h"
#include "udp.h"
/* Convert UDP header in internal format to an mbuf in external format */
struct mbuf *
htonudp(udp,data,ph)
struct udp *udp;
struct mbuf *data;
struct pseudo_header *ph;
{
struct mbuf *bp;
register char *cp;
int16 checksum;
/* Allocate UDP protocol header and fill it in */
if((bp = pushdown(data,UDPHDR)) == NULLBUF)
return NULLBUF;
cp = bp->data;
cp = put16(cp,udp->source); /* Source port */
cp = put16(cp,udp->dest); /* Destination port */
cp = put16(cp,udp->length); /* Length */
*cp++ = 0; /* Clear checksum */
*cp-- = 0;
/* All zeros and all ones is equivalent in one's complement arithmetic;
* the spec requires us to change zeros into ones to distinguish an
* all-zero checksum from no checksum at all
*/
if((checksum = cksum(ph,bp,ph->length)) == 0)
checksum = ~0;
put16(cp,checksum);
return bp;
}
ntohudp(udp,bpp)
struct udp *udp;
struct mbuf **bpp;
{
char udphead[8];
pullup(bpp,udphead,8);
udp->source = get16(udphead);
udp->dest = get16(udphead + 2);
udp->length = get16(udphead + 4);
udp->checksum = get16(udphead + 6);
}